package hh.asm;

/**
 * @author huanghuai
 * @date 2020/11/2
 */
public class AsmUtil {

    public static final String voidReturnType = "()V";




    public static String getClassName(String className) {
        return className.replace(".", "/");
    }
    public static String getClassName(Class clazz) {
        return clazz.getName().replace(".", "/");
    }

    public static String getVoidReturnType( ) {
        return voidReturnType;
    }
    public static String getReturnType(Class clazz) {
        return "(L"+getClassName(clazz.getName())+";)V";
    }

    public static String getType(Class clazz) {
        return "L"+getClassName(clazz.getName())+";";
    }

    public static String getType(Class type, Class... genericTypes) {
        if (genericTypes == null) {
            return getType(type);
        }

        StringBuilder sb = new StringBuilder().append('L').append(getClassName(type.getName())).append('<');
        for (int i = 0; i < genericTypes.length; i++) {
            if (i > 0) {
                sb.append(';');
            }
            sb.append(getType(genericTypes[i]));
        }

        return sb.append(">;").toString();
    }
}
